import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import QtQuick.Dialogs

ApplicationWindow {
    visible: true
    width: 800
    height: 600
    title: "文本编辑器"

    property font editorFont: Qt.font({
        family: "Arial",
        pointSize: 12
    })

    Column {
        anchors.fill: parent
        anchors.margins: 10
        spacing: 10

        ToolBar {
            width: parent.width

            Row {
                spacing: 5

                Button {
                    text: "字体"
                    onClicked: fontDialog.open()
                }

                Button {
                    text: "加粗"
                    checkable: true
                    checked: editorFont.bold
                    onClicked: editorFont.bold = checked
                }

                Button {
                    text: "斜体"
                    checkable: true
                    checked: editorFont.italic
                    onClicked: editorFont.italic = checked
                }

                Button {
                    text: "下划线"
                    checkable: true
                    checked: editorFont.underline
                    onClicked: editorFont.underline = checked
                }
            }
        }

        TextArea {
            id: textEditor
            width: parent.width
            height: parent.height - 50
            text: "在这里输入文本..."
            font: editorFont
            wrapMode: TextEdit.Wrap
        }
    }

    FontDialog {
        id: fontDialog
        title: "选择编辑器字体"
        currentFont: editorFont
        onAccepted: {
            editorFont = selectedFont
        }
    }
}
